<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="是否卡商" prop="isCardVendor">
        <el-select v-model="queryParams.isCardVendor" placeholder="请选择是否卡商" clearable>
          <el-option
            v-for="dict in dict.type.is_or_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="是否实名" prop="isRealnameAuthenticated">
        <el-select v-model="queryParams.isRealnameAuthenticated" placeholder="请选择是否实名认证" clearable>
          <el-option
            v-for="dict in dict.type.is_realname_authenticated"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="姓名" prop="fullName">
        <el-input
          v-model="queryParams.fullName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCardNumber">
        <el-input
          v-model="queryParams.idCardNumber"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['kakabl:extenduser:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['kakabl:extenduser:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['kakabl:extenduser:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['kakabl:extenduser:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="extenduserList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="邀请码" align="center" prop="inviteCode" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="是否实名认证" align="center" prop="isRealnameAuthenticated">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_realname_authenticated" :value="scope.row.isRealnameAuthenticated"/>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="fullName" />
      <el-table-column label="可用卡" align="center" prop="canUserCardNumber" />
      <el-table-column label="身份证号" align="center" prop="idCardNumber" />
      <el-table-column label="剩余余额" align="center" prop="remainingBalance" />
      <el-table-column label="实名认证时间" align="center" prop="realnameAuthenticatedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.realnameAuthenticatedTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column  fixed="right"  label="操作" align="center" class-name="small-padding fixed-width" width="270px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="seeInfo(scope.row)"
            v-hasPermi="['kakabl:extenduser:add']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['kakabl:extenduser:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="addCard(scope.row)"
            v-hasPermi="['kakabl:extenduser:edit']"
          >补卡</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="addSead(scope.row)"
            v-hasPermi="['kakabl:extenduser:edit']"
          >增珠</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['kakabl:extenduser:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改卡卡-用户扩展对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="邀请码" prop="inviteCode">
          <el-input v-model="form.inviteCode" placeholder="请输入邀请码" />
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="是否实名认证" prop="isRealnameAuthenticated">
          <el-select v-model="form.isRealnameAuthenticated" placeholder="请选择是否实名认证">
            <el-option
              v-for="dict in dict.type.is_realname_authenticated"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="姓名" prop="fullName">
          <el-input v-model="form.fullName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idCardNumber">
          <el-input v-model="form.idCardNumber" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="剩余余额" prop="remainingBalance">
          <el-input v-model="form.remainingBalance" placeholder="请输入剩余余额" />
        </el-form-item>
        <el-form-item label="实名认证时间" prop="realnameAuthenticatedTime">
          <el-date-picker clearable
            v-model="form.realnameAuthenticatedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择实名认证时间">
          </el-date-picker>
        </el-form-item>


        <el-form-item label="是否卡商" prop="isCardVendor">
          <el-select v-model="form.isCardVendor" placeholder="请选择是否卡商">
            <el-option
              v-for="dict in dict.type.is_or_no"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>






    <!-- 卡商补卡 -->
    <el-dialog :title="'卡商补卡'" :visible.sync="openCard" width="500px" append-to-body>
      <el-form  label-width="80px">
        <el-form-item label="补卡数量" >
          <el-input type="number" v-model="canUserCardNumber" placeholder="请输入补卡数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAddCard(currentId)">确 定</el-button>
        <el-button @click="openCard=false">取 消</el-button>
      </div>
    </el-dialog>




    <!-- 空投珍珠 -->
    <el-dialog :title="'空投珍珠'" :visible.sync="openSead" width="500px" append-to-body>
      <el-form  label-width="80px">
        <el-form-item label="空投数量" >
          <el-input type="number" v-model="seadNumber" placeholder="请输入空投数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAddSead(currentId)">确 定</el-button>
        <el-button @click="openSead=false">取 消</el-button>
      </div>
    </el-dialog>



    <el-dialog title="激活详细内容" :visible.sync="intiveDetialContent">
      <el-card>
        <div slot="header" class="clearfix">
          <span>激活详情</span>
        </div>
        <el-table :data="intiveOrintiveIng" >
          <el-table-column property="intiveEd" label="激活人数(****)" width="150"></el-table-column>
          <el-table-column property="intive" label="所有邀请人数" width="150"></el-table-column>
        </el-table>
      </el-card>
      <el-card>
        <div slot="header" class="clearfix">
          <span>正在出海数量</span>
        </div>
        <el-table :data="intiveDetialContentData.allSeaRunning">
          <el-table-column property="name" label="名称" width="150"></el-table-column>
          <el-table-column property="size" label="数量" width="150"></el-table-column>
        </el-table>
      </el-card>
      <el-card>
        <div slot="header" class="clearfix">
          <span>全部出海数量（包含出海以及未出海的）</span>
        </div>
        <el-table  :data="intiveDetialContentData.allSea">
          <el-table-column property="name" label="名称" width="150"></el-table-column>
          <el-table-column property="size" label="数量" width="150"></el-table-column>
        </el-table>
      </el-card>

    </el-dialog>


  </div>
</template>

<script>
import {selectDetialSeaAndBeadNumber, listExtenduser, getExtenduser, delExtenduser, addExtenduser, updateExtenduser,addCard,addSead } from "@/api/kakabl/extenduser";

export default {
  name: "Extenduser",
  dicts: ['is_realname_authenticated','is_or_no'],
  data() {
    return {
      intiveOrintiveIng:[{
        intive:'',
        intiveEd:''
      }],
      intiveDetialContentData:{},
      intiveDetialContent:false,
      currentId:'',
      seadNumber:'',
      openSead:false,
      canUserCardNumber:'',
      openCard:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 卡卡-用户扩展表格数据
      extenduserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        inviteCode: null,
        name: null,
        isRealnameAuthenticated: null,
        fullName: null,
        idCardNumber: null,
        remainingBalance: null,
        realnameAuthenticatedTime: null,
        isCardVendor:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        realnameAuthenticatedTime: [
          { required: true, message: "实名认证时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    submitAddSead(id){
      if (!this.seadNumber || this.seadNumber<=0){
        this.$modal.msgSuccess("请输入大于0的数字1");
      }else {
        let param={
          remainingBalance:this.seadNumber,
          id:id
        }
        addSead(param).then(response => {
          if (response.code===200){
            this.$modal.msgSuccess("添加成功");
            this.getList()
            this.openSead = false;
            this.seadNumber='';
          }else {
            this.$modal.msgError("添加失败");
          }
        });
      }
    },
    submitAddCard(id){
      if (!this.canUserCardNumber || this.canUserCardNumber<=0){
        this.$modal.msgSuccess("请输入大于0的数字");
      }else {
        let param={
          canUserCardNumber:this.canUserCardNumber,
          id:id
        }
        addCard(param).then(response => {
          console.log(response)
          if (response.code===200){
            this.$modal.msgSuccess("添加成功");
            this.getList()
            this.openCard = false;
            this.canUserCardNumber='';
          }else {
            this.$modal.msgError("添加失败");
          }
        });
      }
    },
    addCard(item){
      this.currentId = item.id;
      this.openCard = true;
      console.log(item)
    },
    addSead(item){
      this.currentId = item.id;
      this.openSead = true;
      console.log(item)
    },
    /** 查询卡卡-用户扩展列表 */
    getList() {
      this.loading = true;
      listExtenduser(this.queryParams).then(response => {
        this.extenduserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        inviteCode: null,
        name: null,
        isRealnameAuthenticated: null,
        fullName: null,
        idCardNumber: null,
        remainingBalance: null,
        realnameAuthenticatedTime: null
      };

      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加卡卡-用户扩展";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getExtenduser(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改卡卡-用户扩展";
      });
    },
    seeInfo(row){

      let param = {
        userId:row.userId
      }
      selectDetialSeaAndBeadNumber(param).then(response => {
         this.intiveDetialContentData=response.data
         this.intiveOrintiveIng[0].intive=response.data.intivetAllMap
          this.intiveOrintiveIng[0].intiveEd=response.data.intivetMap
          this.intiveDetialContent = true
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateExtenduser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addExtenduser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除卡卡-用户扩展编号为"' + ids + '"的数据项？').then(function() {
        return delExtenduser(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('kakabl/extenduser/export', {
        ...this.queryParams
      }, `extenduser_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
